<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增类型')" />

</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-type-add">
			<div class="form-group">
				<label class="col-sm-3 control-label ">公告类型：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="typeName" id="typeName" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label ">公告描述：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="typeDesc" id="typeDesc" required>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: ztree-js" />
	<script type="text/javascript">

		$("#form-type-add").validate({
			rules:{
				onkeyup: false,
				typeName:{
					remote: {
		                url: ctx + "notice/type/checkTypeNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"typeName" : function() {
		                		return $.common.trim($("#typeName").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				}
			},
			messages: {
		        "typeName": {
		            remote: "类型名称已经存在"
		        }
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	        }
	    }
	
		function add() {
			var typeName = $("input[name='typeName']").val();
			var typeDesc = $("input[name='typeDesc']").val();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "notice/type/typeAdd",
				data : {
					"typeName": typeName,
					"typeDesc": typeDesc
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
	</script>
</body>
</html>
